package org.reenscape.packet;
import org.reenscape.model.*;
import org.reenscape.updater.ClientUpdater;
import org.reenscape.lib.*;
import org.reenscape.*;
import org.reenscape.skill.*;
public class PacketOther {

		/**
		* Packet containing chat text thats updated for other players to see.
		*/
		public void PublicChat(PacketParser p3){
			//If(Muted) return;
			p3.chatTextEffects = p3.inStream.readUnsignedByteS();
			p3.chatTextColor = p3.inStream.readUnsignedByteS();
			p3.chatTextSize = (byte)(p3.packetSize-2);
			p3.inStream.readBytes_reverseA(p3.chatText, p3.chatTextSize, 0);
			p3.chatTextUpdateRequired = true;
			String chatString = Library.mutil.textUnpack(p3.chatText, p3.packetSize-2);
		}
		
		/**
		* The packet that recieves the data from the screen that pops up at initial login.
		*/
		public void CharacterDesign(PacketParser p3){
			int gender = p3.inStream.readSignedByte();
			int head = p3.inStream.readSignedByte();
			int jaw = p3.inStream.readSignedByte();
			int torso = p3.inStream.readSignedByte();
			int arms = p3.inStream.readSignedByte();
			int hands = p3.inStream.readSignedByte();
			int legs = p3.inStream.readSignedByte();
			int feet = p3.inStream.readSignedByte();
			int hairC = p3.inStream.readSignedByte();
			int torsoC = p3.inStream.readSignedByte();
			int legsC = p3.inStream.readSignedByte();
			int feetC = p3.inStream.readSignedByte();
			int skinC = p3.inStream.readSignedByte();
		
			p3.playerLook[0] = gender;
			p3.pHead = head;
			p3.pBeard = jaw;
			p3.pTorso = torso;
			p3.pArms = arms;
			p3.pHands = hands;
		    p3.pLegs = legs;
			p3.pFeet = feet;
			p3.playerLook[1] = hairC;
			p3.playerLook[2] = torsoC;
			p3.playerLook[3] = legsC;
			p3.playerLook[4] = feetC;
			p3.playerLook[5] = skinC;
			p3.design = 1;
			PlayerData.Save(p3);
			p3.appearanceUpdateRequired = true;
		}
		
		/**
		* Removing one item from a selected interface. Used in banks and trade windows.
		*/
		public void RemoveOne(PacketParser p3){
		    int Interface = p3.inStream.readUnsignedWordA();
			int Slot = p3.inStream.readUnsignedWordA();
			int ID = p3.inStream.readUnsignedWordA();
			
			if(Interface == 1688) {
				if(p3.playerEquipment[Slot] > 0) {
					p3.remove(ID , Slot);
				}
			}
			else if(Interface == 5064) { //Inventory to bank
				p3.bankItem(ID, Slot, 1);
			} else if(Interface == 5382) { //Bank to Inventory
				p3.fromBank(ID, Slot, 1);
			} else if(Interface == 3322) { //Inventory to trade window
				if(ID == 6556 || p3.isUntradable(ID)) {
					p3.sendMessage("You cannot trade this item.");
				} else{
        		p3.tradeItem(ID , Slot, 1);
				}
			} else if(Interface == 3415) { //Trade window to Inventory
				p3.fromTrade(ID, Slot, 1);
			} else if(Interface == 3823) { //Shop item sell value
				if(Item.itemSellable[ID] == false) {
					p3.sendMessage("I cannot sell "+p3.GetItemName(ID)+".");
				} else {
					boolean IsIn = false;
					if(Server.shopHandler.ShopSModifier[p3.MyShopID] > 1) {
						for(int j = 0; j <= Server.shopHandler.ShopItemsStandard[p3.MyShopID]; j++) {
							if(ID ==(Server.shopHandler.ShopItems[p3.MyShopID][j] - 1)) {
								IsIn = true;
								break;
							}
						}
					} else {
						IsIn = true;
					}
					if(IsIn == false) {
						p3.sendMessage("You cannot sell "+p3.GetItemName(ID)+" in this store.");
					} else {
						int ShopValue =(int)Math.floor(p3.GetItemShopValue(ID, 1, Slot));
						String ShopAdd = "";
						if(ShopValue <= 1) {
							ShopValue =(int)Math.floor(p3.GetItemShopValue(ID, 0, Slot));
						}
						if(ShopValue >= 1000 && ShopValue < 1000000) {
							ShopAdd = "(" +(ShopValue / 1000) + "K)";
						} else if(ShopValue >= 1000000) {
							ShopAdd = "(" +(ShopValue / 1000000) + " million)";
						}
						p3.sendMessage(p3.GetItemName(ID)+": shop will buy for "+ShopValue+" coins"+ShopAdd);
					}
				}
			} else if(Interface == 3900) { //Show value to buy items
				int ShopValue =(int)Math.floor(p3.GetItemShopValue(ID, 0, Slot));
				String ShopAdd = "";
				if(ShopValue <= 1) {
					ShopValue =(int)Math.floor(p3.GetItemShopValue(ID, 0, Slot));
				}
				if(ShopValue >= 1000 && ShopValue < 1000000) {
					ShopAdd = "(" +(ShopValue / 1000) + "K)";
				} else if(ShopValue >= 1000000) {
					ShopAdd = "(" +(ShopValue / 1000000) + " million)";
				}
				p3.sendMessage(p3.GetItemName(ID)+": currently costs "+ShopValue+" coins"+ShopAdd);
			} else if(Interface == 1119) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 1);
			} else if(Interface == 1120) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 1);
			} else if(Interface == 1121) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 1);
			} else if(Interface == 1122) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 1);
			} else if(Interface == 1123) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 1);
			}
		}
		
		/**
		* Removing five items from an interface, like banks or trade windows.
		*/
		public void RemoveFive(PacketParser p3){
			int Interface = p3.inStream.readSignedWordBigEndianA();
			int ID = p3.inStream.readSignedWordBigEndianA();
			int Slot = p3.inStream.readSignedWordBigEndian();
			
			if(Interface == 5064) { //Inventory to Bank
				p3.bankItem(ID, Slot, 5);
			} else if(Interface == 5382) { //Bank to Inventory
				p3.fromBank(ID, Slot, 5);
			} else if(Interface == 3322) { //Inventory to Trade window
				if(p3.isUntradable(ID))
					p3.sendMessage("You cannot trade this item.");
				else
					p3.tradeItem(ID, Slot, 5);
			} else if(Interface == 3415) { //Trade window to Inventory
				p3.fromTrade(ID, Slot, 5);
			} else if(Interface == 3823) { //Show value to sell items
				p3.sellItem(ID, Slot, 1);
			} else if(Interface == 3900) { //Show value to buy items
				p3.buyItem(ID, Slot, 1);		
			} else if(Interface == 1119) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 5);
			} else if(Interface == 1120) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 5);
			} else if(Interface == 1121) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 5);
			} else if(Interface == 1122) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 5);
			} else if(Interface == 1123) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 5);
			}
		}
		
		/**
		* Removing ten items from an interface, like banks or trade windows.
		*/
		public void RemoveTen(PacketParser p3){
			int Interface = p3.inStream.readUnsignedWordBigEndian();
			int ID = p3.inStream.readUnsignedWordA();
			int Slot = p3.inStream.readUnsignedWordA();

			if(Interface == 5064) { // Inventory to Bank
				p3.bankItem(ID, Slot, 10);
			} else if(Interface == 5382) { //Bank to Inventory
				p3.fromBank(ID, Slot, 10);
			} else if(Interface == 3322) { //Inventory to Trade window
				if(p3.isUntradable(ID))
					p3.sendMessage("You cannot trade this item.");
				else
					p3.tradeItem(ID , Slot, 10);
			} else if(Interface == 3415) { //Trade window to Inventory
				p3.fromTrade(ID, Slot, 10);
			} else if(Interface == 3823) { //Show value to sell items
				p3.sellItem(ID, Slot, 5);
			} else if(Interface == 3900) { //Show value to buy items
				p3.buyItem(ID, Slot, 5);
			} else if(Interface == 1119) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 10);
			} else if(Interface == 1120) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 10);
			} else if(Interface == 1121) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 10);
			} else if(Interface == 1122) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 10);
			} else if(Interface == 1123) {
				Skill.smithing.smithingMain(p3, Slot, Interface, ID, 10);
			}
		}
		
		/**
		* Selecting 'Remove All' on some interfaces like banks.
		*/
		public void RemoveAll(PacketParser p3){
			int Slot = p3.inStream.readUnsignedWordA();
			int Interface = p3.inStream.readUnsignedWord();
			int ID = p3.inStream.readUnsignedWordA();
    
			if(Interface == 5064) { //Inventory to Bank
				if(Item.itemStackable[ID] == true) {
					p3.bankItem(p3.playerItems[Slot] , Slot, p3.playerItemsN[Slot]);
				} else {
					p3.bankItem(p3.playerItems[Slot] , Slot, p3.itemAmount(p3.playerItems[Slot]));
				}
			} else if(Interface == 5382) { //Bank to Inventory
				p3.fromBank(p3.bankItems[Slot] , Slot, p3.bankItemsN[Slot]);
			} else if(Interface == 3322) { //Inventory to Trade window
				if(p3.isUntradable(ID))
					p3.sendMessage("You cannot trade this item.");
				else
					p3.tradeItem(ID, Slot, p3.playerItemsN[Slot]);
			} else if(Interface == 3415) { //Trade window to Inventory
				p3.fromTrade(ID, Slot, p3.playerItemsN[Slot]);
			} else if(Interface == 3823) { //Show value to sell items
				p3.sellItem(ID, Slot, 10);
			} else if(Interface == 3900) { //Show value to buy items
				p3.buyItem(ID, Slot, 10);
			}		
		}
		
		/**
		* Removing X from a specific interface.
		*/
		public void RemoveX(PacketParser p3){
			p3.outStream.createFrame(27);
			p3.XremoveSlot = p3.inStream.readSignedWordBigEndian();
			p3.XinterfaceID = p3.inStream.readUnsignedWordA();
			p3.XremoveID = p3.inStream.readSignedWordBigEndian();
		}
		
		/**
		* Removing an X amount of items from the bank or trade window.
		*/
		public void PutX(PacketParser p3){
			int Amount = p3.inStream.readDWord();
			
			if(p3.XinterfaceID == 5064) { //Inventory to Bank
				p3.bankItem(p3.playerItems[p3.XremoveSlot], p3.XremoveSlot, Amount);
			} else if(p3.XinterfaceID == 5382) { //Bank to Inventory
				p3.fromBank(p3.bankItems[p3.XremoveSlot], p3.XremoveSlot, Amount);
			} else if(p3.XinterfaceID == 3322) { //Inventory to Trade window
				p3.tradeItem(p3.XremoveID, p3.XremoveSlot, Amount);
			} else if(p3.XinterfaceID == 3415) { //Trade window to Inventory
				p3.fromTrade(p3.XremoveID, p3.XremoveSlot, Amount);
			}
		}
		
		/**
		* Triggered when an interface is closed that contains operations, like a trade window.
		*/
		public void CloseInterface(PacketParser p3){
			int Interface = p3.inStream.readUnsignedWordA();
			
				if (p3.tradeStatus >= 2) {
					ClientUpdater.players[p3.tradeWith].tradeOtherDeclined = true;
					p3.DeclineTrade();
					p3.sendMessage("You decline the trade.");
				}
				if (p3.IsShopping == true) {
					p3.IsShopping = false;
					p3.MyShopID = 0;
					p3.UpdateShop = false;
				}
				if (p3.IsBanking == true) {
					p3.IsBanking = false;
				}
		}
		
		/**
		* Supposivly burning fires, not known at the moment.
		*/
		public void BurnFire(PacketParser p3){
			int X = p3.inStream.readSignedWordBigEndian();
			int Y = p3.inStream.readUnsignedWordBigEndianA();
			int ID = p3.inStream.readSignedWordA();
			
		}
}